﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Components.Enum;
using UI.SellOrder;

namespace UI.BuyManagement
{
    public partial class FrmPurchaseReturn : UI.ParentForm.BaseMain
    {
        FrmPurchaseReturnMedit edit = null;

        public FrmPurchaseReturn(string modulecode, string action)
            : base(modulecode, action)
        {
            InitializeComponent();
        }

        protected override void AddToolButton()
        {
            this.tspAdd.Text = "退 货";
        }

        protected override void OnAddClick(ToolStripButton btn)
        {
            edit = new FrmPurchaseReturnMedit(this.ModuleCode, "A", GetTitleStyle(this.Text, btn.Text), "");
            edit.ShowDialog();
            if (edit.IsReload) base.BindGrid();
        }

        protected override void UpdatePager(UI.Common.Pager pager)
        {
            pager.FilterAppName = "a.usercode";
            pager.StrWhere = string.Format(" a.doctype = '{0}' ", DocumentType.PurchaseReturn);
        }

        protected override void OnViewClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("V", btn.Text, Components.Validation.ToString(row.Cells["listid"].Value));
        }

        protected override void OnEditClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("M", btn.Text, Components.Validation.ToString(row.Cells["listid"].Value));
        }

        private void OpenEdit(string action, string btnText, string code)
        {
            edit = new FrmPurchaseReturnMedit(this.ModuleCode, action, GetTitleStyle(this.Text, btnText), code);
            edit.ShowDialog();
            if (edit.IsReload) base.BindGrid();
        }
    }
}
